package hotLeetcode;

import java.util.Arrays;

public class H04Leetcode {
    public double findMedianSortedArrays(int[] nums1, int[] nums2) {

        int len = nums1.length + nums2.length;
        int[] arr = new int[len];
        for (int i = 0; i < nums1.length; i++) {
            arr[i] = nums1[i];
        }
        for (int i = nums1.length , j = 0; j < nums2.length; j++, i++) {
            arr[i] = nums2[j];
        }

        Arrays.sort(arr);
        if (arr.length % 2 != 0) {
            return arr[arr.length / 2];

        } else {
            return (double) (arr[arr.length / 2] + arr[arr.length / 2 - 1]) /2;
        }

    }

    public static void main(String[] args) {
        H04Leetcode h04Leetcode = new H04Leetcode();
        int[] nums1 = new int[]{1, 2, 3};
        int[] nums2 = new int[]{1, 4};
        h04Leetcode.findMedianSortedArrays(nums1, nums2);
    }
}
